<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>引合一覧管理</title>
<%@ include file="/common/header/meta.jsp"%>
<%@ include file="/common/header/script.jsp"%>
<script type="text/javascript">
	var $dg;
	$(function() {
		$dg = $("#dg").datagrid({
			url: $.webapp.root+"/admin/oa/yhyl/datagrid.do",
			title: '<span style="font-weight:normal;color:#666;">引合一覧管理</span>', 
			idField: 'id', fit: true, border: false, pageSize: 30, pageList: [30,40,50,100,200,1000	], rownumbers: true,
			remoteSort: true, toolbar: '#toolbars', striped:true, pagination: true, singleSelect: false,
			sortName: 'num', sortOrder: 'asc',
			frozenColumns: [[
			    { field: 'ck', checkbox: true },
			    { field: 'id', title: 'ID', width: 80, hidden: true },
			    { field: 'yhId', title: '引合ID', width: 100, sortable: true},
			]],
			columns: [[
			    { field: 'ajmc', title: '案件名', width: 300 },
			    { field: 'ajzl', title: '案件種別', width: 100 },
			    { field: 'client', title: '客先', width: 100 },
			    { field: 'szzk', title: '受注状態', width: 100 },
			    { field: 'projectId', title: '项目ID', width: 100, sortable: true },
			    { field: 'ksyd', title: '開始予定 ', width: 100, formatter:function(value, row, index){
					if(undefined != value) {
						return $.date.format(value, "yyyy-MM-dd") ;
					} 
				} },
			    { field: 'jsyd', title: '終了予定', width: 100, formatter:function(value, row, index){
					if(undefined != value) {
						return $.date.format(value, "yyyy-MM-dd") ;
					} 
				} },
			    { field: 'htpszk', title: '合同評審状況', width: 100 },
			    { field: 'taz', title: '提案者', width: 100 },
			    { field: 'org_name', title: '責任部門', width: 100 },
			    { field: 'bz', title: '部長', width: 100 },
			    { field: 'xmxsKz', title: '项目系数（K值）', width: 100 },
			    { field: 'remark', title: '備考', width: 100 },
			    { field: 'created', title: '创建时间', width: 140 },
 			    { field: 'createName', title: '创建者', width: 140 },
 			    { field: 'modifyDate', title: '最后修改时间', width: 140 },
 			    { field: 'modifyName', title: '修改者', width: 140 }
			]],
			onLoadSuccess: function(node, data) {
				$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
				$dg.datagrid('unselectAll');$dg.datagrid('clearSelections');
				
				//合并列表
				mergeCells(node, data) ; 
			}
		}) ;
		
		function mergeCells(node, data) {
			/* var merges = [{
                index: 0,
                rowspan: 3
            }];
            for(var i=0; i<merges.length; i++){
            	$dg.datagrid('mergeCells',{
                    index: merges[i].index,
                    field: 'projectId',
                    rowspan: merges[i].rowspan
                }); 
            } */
		}
		
		org_search = $("#org_search").combotree({
			url : $.webapp.root+"/static_res/org.tree.json",
			editable: false, lines:true,
			onChange: function(newValue, oldValue) {
				$dg.datagrid("load",{org_id: newValue});
				
            }
	    });
		
		var data = {"dictCode": "YHYL_AJLB,YHYL_SZZT,YHYL_HTPSZK"} ;
		$.post($.webapp.root+"/admin/system/dict/doNotNeedSession_dictAttrMaps.do", data, function(result) {
			$("#YHYL_AJLB").combobox({
				editable: false, required:false,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.YHYL_AJLB
			}) ;
			/* $("#YHYL_SZZT").combobox({
				editable: false, required:false,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.YHYL_SZZT
			}) ; */
			$("#YHYL_KX").combobox({
				editable: false, required:false,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.YHYL_KX
			}) ;
			$("#YHYL_HTPSZK").combobox({
				editable: false, required:false,
				valueField: 'text', textField: 'text', panelHeight: 'auto', data: result.YHYL_HTPSZK
			}) ;
		}, 'json');
	});
	
	function doSearch(value,name){
		var o = {} ; o[name] = value ; $dg.datagrid("load",o);
	}
	function searchBox() {
		var search_form = $("#searchForm").form("getData") ;
		$dg.datagrid("load",search_form);
	}
	function searchClear() {
		$("#searchForm").form("clear") ;
		$dg.datagrid("load",{});
	}
	
	function form_edit(form) {
		var form_url = $.webapp.root+"/admin/oa/yhyl/yhyl_form_UI.do" ;
		if("E" == form) {
			var node = $dg.datagrid('getSelected');
			if (node) {
				if(node.id == undefined || "" == node.id) {
					alertify.warning("未创建账号，不可以编辑！"); return ;
				}
				form_url = $.webapp.root+"/admin/oa/yhyl/yhyl_form_UI.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true,
			width: 750, height: 405, maximizable: true,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '保存并继续', iconCls : 'icon-standard-disk', handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		} else {
			alertify.warning("请选择一条记录！");
			return false;
		}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				$.post($.webapp.root+"/admin/oa/yhyl/delete.do", {"ids" : ids.join(',')}, function(result) {
					if (result.status) {
						$dg.datagrid('unselectAll');$dg.datagrid('reload') ;
						alertify.success(result.msg);
						$.easyui.loaded();
					} else {
						alertify.warning(result.msg);
						$.easyui.loaded();
					}
				}, 'json').error(function() { $.easyui.loaded(); });
			}
		});
	}
	
	
	function batch_role() {
		var ids = [];
		var rows = $dg.datagrid('getChecked');
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		} else {
			alertify.warning("请选择一条记录！");
			return ;
		}
		if(ids.length<1) { alertify.warning("请选择已创建账号的记录！"); return ;}
		var $d = $.easyui.showDialog({
			href: $.webapp.root+"/admin/oa/yhyl/yhyl_batch_projectid_UI.do", 
			title: "批量设置项目ID", iniframe: false, topMost: true, width: 400, height: 230,
            enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
            buttons : [ 
              { text : '确定', iconCls : 'ext_save', handler : function() { $.easyui.parent.submitForm($d, $dg); } },
              { text : '关闭', iconCls : 'ext_cancel', handler : function() { $d.dialog('destroy'); } } 
           	],
           	onLoad: function(){
           		parent.$("#ids").val(ids.join(","));
           	}
        });
	}
	
</script>
</head>

<body>

	<div id="dg">
		<div id="toolbars">
            <a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
            <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
            <a onClick="del();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
            <a onclick="$dg.datagrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
            <a onClick="$dg.datagrid('unselectAll');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-application-xp'">取消选中</a>
        	<a onclick="batch_role();" class="easyui-linkbutton" data-options="plain: true, iconCls:'icon-hamburg-hire-me'">批量设置项目ID</a>
            <a onClick="searchBox();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-zoom'">查询</a>
			<a onClick="searchClear();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'icon-standard-zoom-out'">重置</a>
            <div id="search_bar">
            	<form id="searchForm">
	            	<div class="s_box">
	            		<div class="gr">
		            		<div class="st">公司</div>
		            		<div class="si1"><input id="org_search" name="org_id" style="width:200px;height:25px;" /></div>
	            		</div>
	            		<div class="gr">
							<div class="st">開始予定</div>
							<div class="si1">
								<input id="d4311" name="ksStartDate" class="Wdate" style="height:23px;" type="text" onFocus="WdatePicker({
									isShowClear:true,
									readOnly:true,
									maxDate:'#F{$dp.$D(\'d4312\')||\'2020-10-01\'}'
									})"/>
								至
								<input id="d4312" name="ksEndDate" class="Wdate" style="height:23px;" type="text" onFocus="WdatePicker({
									isShowClear:true,
									readOnly:true,
									minDate:'#F{$dp.$D(\'d4311\')}',
									maxDate:'2120-10-01'
									})"/>
		            		</div>
		            	</div>
	            		<div class="gr">
							<div class="st">終了予定</div>
							<div class="si1">
								<input id="2d4311" name="jsStartDate" class="Wdate" style="height:23px;" type="text" onFocus="WdatePicker({
									isShowClear:true,
									readOnly:true,
									maxDate:'#F{$dp.$D(\'2d4312\')||\'2020-10-01\'}'
									})"/>
								至
								<input id="2d4312" name="jsEndDate" class="Wdate" style="height:23px;" type="text" onFocus="WdatePicker({
									isShowClear:true,
									readOnly:true,
									minDate:'#F{$dp.$D(\'2d4311\')}',
									maxDate:'2120-10-01'
									})"/>
		            		</div>
		            	</div>
	            	</div>
	            	
	            	<div class="s_box">
	            		<div class="gr">
		            		<div class="si">
			            		<input class="easyui-searchbox" data-options="searcher:doSearch,width: 220, height: 25, menu: '#topSearchboxMenu'" />
								<div id="topSearchboxMenu" style="width: 85px;">
									<div data-options="name:'yhId', iconCls: 'icon-hamburg-zoom'">案件编号</div>
									<div data-options="name:'ajmc', iconCls: 'icon-hamburg-zoom'">案件名称</div>
									<div data-options="name:'projectId', iconCls: 'icon-hamburg-zoom'">项目ID</div>
								</div>
		            		</div>
	            		</div>
	            		<div class="gr">
							<div class="st">案件种类</div>
							<div class="si">
								<input id="YHYL_AJLB" name="ajzl" type="text" class="easyui-combobox" />
							</div>
						</div>
	            		<!-- <div class="gr">
							<div class="st">客先</div>
							<div class="si">
								<input id="YHYL_KX" name="client" type="text" class="easyui-combobox"/>
							</div>
						</div> -->
	            		<div class="gr">
							<div class="st">受主状况</div>
							<div class="si">
								<input id="YHYL_SZZT" name="szzk" type="text" class="easyui-combobox"/>
							</div>
						</div>
	            		<div class="gr">
							<div class="st">合同审批状态</div>
							<div class="si">
								<input id="YHYL_HTPSZK" name="htpszk" type="text" class="easyui-combobox" style="width:100px;"/>
							</div>
						</div>
	            	</div>
            	</form>
            </div>
        </div>
	</div>
	<iframe id="download" style="display:none"></iframe> 
</body>
</html>